package com.sale.goods.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.goods.domain.dto.GoodsCostDto;
import com.sale.goods.domain.vo.GoodsCostVo;
import com.sale.goods.service.IGoodsCostService;
import com.sale.goods.service.IGoodsCostService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 成本调整
 * @Date 23-08-08
 * @Author hl
 **/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/cost")
public class GoodsCostController extends BaseController {

    private final IGoodsCostService goodsCostService;

    /**
     * 获取其他支出单
     */
    //@SaCheckPermission("goods:Cost:list")
    @GetMapping("/list")
    public TableDataInfo<GoodsCostDto> list(GoodsCostVo goodsCostVo, PageQuery pageQuery)
    {
        return goodsCostService.selectCostList(goodsCostVo,pageQuery);
    }

    /**
     * 新增其他支出单
     */
    //@SaCheckPermission("goods:Cost:add")
    @Log(title = "其他支出单", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody GoodsCostVo goodsCostVo){
        return toAjax(goodsCostService.insertCost(goodsCostVo));
    }

    /**
     * 根据编号获取详细信息
     */
    @GetMapping(value = "/{CostId}")
    public R getInfo(@PathVariable long CostId)
    {
        return R.ok(goodsCostService.selectCostById(CostId));
    }

    /**
     * 删除收款单
     */
    //@SaCheckPermission("goods:Cost:remove")
    @Log(title = "其他支出单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{CostId}")
    public R<Void> remove(@PathVariable("CostId") Long CostId) {
        return toAjax(goodsCostService.deleteCostById(CostId));
    }

    /**
     * 修改收款单
     */
    //@SaCheckPermission("goods:Cost:edit")
    @Log(title = "其他支出单", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody GoodsCostVo goodsCostVo) {
        return toAjax(goodsCostService.updateCostEdit(goodsCostVo));
    }

    /**
     * 提交审核
     */
    //@SaCheckPermission("goods:collectionId:subExamine")
    @Log(title = "其他支出单", businessType = BusinessType.UPDATE)
    @GetMapping("/submitReview/{CostId}")
    public R<Void> submitReview(@PathVariable("CostId") Long CostId) {
        return toAjax(goodsCostService.submitReview(CostId));
    }

    /**
     * 撤销审核
     */
    //@SaCheckPermission("goods:Collection:revoke")
    @Log(title = "其他支出单", businessType = BusinessType.UPDATE)
    @GetMapping("/deleteReview/{CostId}")
    public R<Void> deleteReview(@PathVariable("CostId") Long CostId) {
        return toAjax(goodsCostService.deleteReview(CostId));
    }

    /**
     * 审核单据
     */
    //@SaCheckPermission("goods:Collection:review")
    @Log(title = "其他支出单", businessType = BusinessType.UPDATE)
    @PostMapping("/examine")
    public R<Void> examine(@Validated @RequestBody GoodsCostVo goodsCostVo) throws Exception {
        return toAjax(goodsCostService.goodSExamineReview(goodsCostVo));
    }

}
